
package com.gzbsoft.sc.modules.sys.controller;
import com.gzbsoft.sc.common.annotation.SysLog;
import com.gzbsoft.sc.common.utils.R;
import com.gzbsoft.sc.modules.sys.entity.SysMenu;
import com.gzbsoft.sc.modules.sys.service.SysMenuService;
import io.swagger.annotations.Api;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.List;
@Api("系统菜单")
@RestController
@RequestMapping("/sys/menu")
public class SysMenuController extends AbstractController {
    private final SysMenuService sysMenuService;
    public SysMenuController(SysMenuService sysMenuService) {
        this.sysMenuService = sysMenuService;
    }
    @GetMapping("/nav")
    public R nav() {
        return R.ok();
    }
    @GetMapping("/list")
    @RequiresPermissions("sys:menu:list")
    public R list(SysMenu sysMenu, @PageableDefault Pageable page) {
        return R.ok().setPage(sysMenuService.page(sysMenu, page));
    }
    @GetMapping("/tree")
    @RequiresPermissions("sys:menu:select")
    public R tree() {
        List<SysMenu> menuList = sysMenuService.menuTree(0L);
        return R.ok().setList(menuList);
    }
    @GetMapping("/{id}")
    @RequiresPermissions("sys:menu:info")
    public R info(@PathVariable Long id) {
        return R.ok().setObj(null);
    }
    @SysLog("保存菜单")
    @PutMapping("/")
    @RequiresPermissions("sys:menu:save")
    public R save(@NotNull @RequestBody SysMenu menu) {
        //TODO 数据校验
        sysMenuService.save(menu);
        return R.ok();
    }
    @SysLog("修改菜单")
    @PostMapping("/")
    @RequiresPermissions("sys:menu:update")
    public R update(@RequestBody SysMenu menu) {
        //TODO 数据校验
        sysMenuService.update(menu);
        return R.ok();
    }
    @SysLog("删除菜单")
    @DeleteMapping("/")
    @RequiresPermissions("sys:menu:delete")
    public R deleteBatch(Long[] menuIds) {
        sysMenuService.deleteBatch(menuIds);
        return R.ok();
    }
}
